package com.mysoft.gfyx.marketdevelop.service.impl;

import com.google.common.base.Joiner;
import com.mingyuanyun.sdk.mip.exception.MipSdkException;
import com.mysoft.framework.cache.api.CacheProvider;
import com.mysoft.framework.common.exception.BusinessLogicException;
import com.mysoft.framework.common.user.User;
import com.mysoft.framework.context.api.ContextManager;
import com.mysoft.framework.core.function.authorization.AuthenticationUser;
import com.mysoft.framework.modeling.dto.LabelStyleConfig;
import com.mysoft.framework.modeling.dto.ListDataResult;
import com.mysoft.framework.service.AppService;
import com.mysoft.gfyx.common.dto.ListResult;
import com.mysoft.gfyx.common.rpc.bigdata.BigDataClientFactoryService;
import com.mysoft.gfyx.common.rpc.bigdata.BigDataClientService;
import com.mysoft.gfyx.common.rpc.bigdata.dto.GetPurchaseDetailRequestDto;
import com.mysoft.gfyx.common.rpc.bigdata.dto.GetPurchaseDetailResponseDto;
import com.mysoft.gfyx.common.rpc.openapi.OpenapiClientFactoryService;
import com.mysoft.gfyx.common.rpc.openapi.OpenapiClientService;
import com.mysoft.gfyx.common.rpc.openapi.dto.ApplyMainDataReqDto;
import com.mysoft.gfyx.common.rpc.openapi.dto.ApplyMainDataRespDto;
import com.mysoft.gfyx.common.rpc.opensearch.OpensearchClientFactoryService;
import com.mysoft.gfyx.common.rpc.opensearch.OpensearchClientService;
import com.mysoft.gfyx.common.rpc.opensearch.dto.GetDeveloperScoreRequestDto;
import com.mysoft.gfyx.common.rpc.opensearch.dto.OpenSearchSingleListResponseDto;
import com.mysoft.gfyx.common.rpc.opptyservice.dto.OpptyServiceResponseDto;
import com.mysoft.gfyx.common.time.TimeService;
import com.mysoft.gfyx.common.util.MyStringUtil;
import com.mysoft.gfyx.common.util.OssUtil;
import com.mysoft.gfyx.common.ycg.YcgFileService;
import com.mysoft.gfyx.marketdevelop.controller.dto.ApplyDeveloperMainDataDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.CreditCodeBaseRequestDto;
import com.mysoft.gfyx.marketdevelop.mip.GetDeveloperDataService;
import com.mysoft.gfyx.marketdevelop.mip.agent.GetDeveloperDataServiceAgent;
import com.mysoft.gfyx.marketdevelop.mip.agent.dto.InvenstmentRelationCacheDto;
import com.mysoft.gfyx.marketdevelop.mip.dto.*;
import com.mysoft.gfyx.marketdevelop.mip.dto.TjCustom.*;
import com.mysoft.gfyx.marketdevelop.mip.dto.TjMetric.QueryMetricRequestDto;
import com.mysoft.gfyx.marketdevelop.remoteService.RemoteClueService;
import com.mysoft.gfyx.marketdevelop.remoteService.RemoteCustomerService;
import com.mysoft.gfyx.marketdevelop.remoteService.RemoteSubscriptionService;
import com.mysoft.gfyx.marketdevelop.remoteService.dto.*;
import com.mysoft.gfyx.marketdevelop.service.*;
import com.mysoft.gfyx.marketdevelop.service.dto.*;
import com.mysoft.sdk.context.core.ThreadContextHolder;
import groovy.util.logging.Log4j;
import io.swagger.models.auth.In;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class DeveloperServiceImp extends AppService implements DeveloperService {

    @Value("${tjdata.project_code}")
    private String project_code;

    @Value("${tjdata.entities.developer}")
    private String developerEntity;

    @Value("${tjdata.entities.takingland}")
    private String takingLandEntity;

    @Value("${tjdata.entities.project}")
    private String projectEntity;

    @Resource
    private Environment environment;

    @Resource
    private CacheProvider cacheProvider;

    @Autowired
    private GetDeveloperDataService getDeveloperDataService;

    @Autowired
    private GetDeveloperDataServiceAgent getDeveloperDataServiceAgent;

    @Autowired
    private OpenapiClientFactoryService openapiClientFactoryService;

    @Autowired
    private ContextManager contextManager;

    @Autowired
    private TimeService timeService;

    @Autowired
    private RemoteCustomerService remoteCustomerService;

    @Autowired
    private RemoteClueService clueService;

    @Autowired
    private YcgFileService ycgFileService;

    @Autowired
    private LabelService labelService;

    @Autowired
    private MetricService metricService;

    @Autowired
    private SearchService searchService;

    @Autowired
    private CommonService commonService;

    @Autowired
    BigDataClientFactoryService bigDataClientFactoryService;

    @Autowired
    private RemoteSubscriptionService remoteSubscriptionService;
    @Autowired
    private OpensearchClientFactoryService opensearchClientFactoryService;

    DeveloperServiceImp() {

    }

    public ListResult<Map<String, Object>> getDeveloperFeeds(String creditCode) {
        if (creditCode == null || creditCode.equals("")) {
            return new ListResult<>();
        }
        GetDeveloperFeedsRequestDto getDeveloperFeedsRequestDto = new GetDeveloperFeedsRequestDto();
        getDeveloperFeedsRequestDto.setOrganizing_code(creditCode);
        getDeveloperFeedsRequestDto.setPageNum(1);
        SqlApiResponseDto res = getDeveloperDataService.getDeveloperFeeds(getDeveloperFeedsRequestDto);

        ListResult<Map<String, Object>> data = new ListResult<>();
        data.setData(res.getData().getRows());
        data.setTotal(res.getData().getTotalNum());

        return data;
    }

    public DeveloperActivityRadarDto getActivityRadar(String creditCode, DeveloperMetricDto metric) {
        DeveloperActivityRadarDto radar = new DeveloperActivityRadarDto();

        DeveloperActivityRadarDto fullSocre = getFullActivityRadar();
        if (metric.getNearly_a_year_taken_land() > 0)
            radar.setTake_land_score(Math.log(metric.getNearly_a_year_taken_land()) / fullSocre.getTake_land_score());
        if (metric.getNearly_a_year_open_project() > 0)
            radar.setProject_score(Math.log(metric.getNearly_a_year_open_project()) / fullSocre.getProject_score());
        if (metric.getCommence_permit_cnt_1year() > 0)
            radar.setCommence_permit_score(Math.log(metric.getCommence_permit_cnt_1year()) / fullSocre.getCommence_permit_score());

        return radar;
    }

    protected DeveloperActivityRadarDto getFullActivityRadar() {

        String cacheKey = "MARKETDEVELOP:DEVELOPER:ACTIVITYFULLSCORE";
        DeveloperActivityRadarDto radar = cacheProvider.get(cacheKey);
        if (radar != null) {
            return radar;
        }

        radar = new DeveloperActivityRadarDto();
        radar.setTake_land_score(Math.log(metricService.getMaxTakingLandNumber()));
        radar.setProject_score(Math.log(metricService.getMaxOpeningProjectNumber()));
        radar.setCommence_permit_score(Math.log(metricService.getMaxCommenceNumber()));

        cacheProvider.set(cacheKey, radar, 36000);
        return radar;
    }

    public Object searchDeveloper(SearchDeveloperRequestDto dto) {
        BasicOpensearchResponse res = getDeveloperDataService.searchDeveloper(dto.getKeyword(), dto.getProvince_code(), dto.getCity_code(), dto.getCompany_type(), dto.getProject_type(), dto.getLand_type(), dto.getDeveloper_activity_label(), dto.getDeveloper_top_100_label(), dto.getIs_new_decorate_expand_label(), dto.getIs_new_land_usage_expand_label(), dto.getIs_new_area_expand_label(), dto.getHigh_project_customers_label(), dto.getIs_ycg_certification(), dto.getIs_ycg_offline_business_connect(), dto.getIndustry_category_middle(), dto.getPage(), dto.getPageSize());
        //
        return res.getData();
    }

    public Object searchEnterpriseName(String keyword) {
        BasicYcgListWithoutTotalResponseDto res = getDeveloperDataService.searchEnterpriseName(keyword);
        return res.getData();
    }

    public Object searchOpportunityName(String keyword) {
        BasicYcgListWithoutTotalResponseDto res = getDeveloperDataService.searchOpportunityName(keyword);
        return res.getData();
    }

    public Object searchLandName(String keyword) {
        BasicYcgListWithoutTotalResponseDto res = getDeveloperDataService.searchLandName(keyword);
        return res.getData();
    }

    public Object searchCommencePermitName(String keyword) {
        BasicYcgListWithoutTotalResponseDto res = getDeveloperDataService.searchCommencePermitName(keyword);
        return res.getData();
    }

    public Object searchProjectName(String keyword) {
        BasicYcgListWithoutTotalResponseDto res = getDeveloperDataService.searchProjectName(keyword);
        return res.getData();
    }

    public Object searchWinBidName(String keyword) {
        BasicYcgListWithoutTotalResponseDto res = getDeveloperDataService.searchWinBidName(keyword);
        return res.getData();
    }

    public Object getCertificates(CreditCodeBaseRequestDto dto) {
        BasicYcgOpenApiRequestDto req = new BasicYcgOpenApiRequestDto();
        req.setKeyword(dto.getCreditCode());
        req.setPage_num(dto.getPager().getPage());
        req.setPage_size(dto.getPager().getPage_size());
        BasicOpensearchResponse res = getDeveloperDataService.getCertificate(req);
        return res.getData();
    }

    public ArrayList<String> getSubCompanyByInvestment(String creditCode) {

        InvenstmentRelationCacheDto res = getDeveloperDataServiceAgent.getFormativeInvestment(creditCode);

        ArrayList<String> creditCodes = new ArrayList<>();

        res.getList().forEach(investment -> {
            creditCodes.add(investment.getCreditCode());
        });

        return creditCodes;
    }

    public Object getInvestment(GetInvestmentRequestDto dto) {
        InvenstmentRelationCacheDto res = getDeveloperDataServiceAgent.getFormativeInvestment(dto.getCredit_code());
        return res;
    }

    public <T extends BaseTjRequestDto> T setCommonData(T dto) {
        setCommonData(dto, TjEntity.Developer);
        return dto;
    }

    public <T extends BaseTjRequestDto> T setCommonData(T dto, TjEntity entityFlag) {
        dto.setProject_code(this.project_code);
        dto.setEntity_id(getEntityId(entityFlag));
        return dto;
    }

    public String getEntityId(TjEntity entityFlag) {
        String entityId;
        switch (entityFlag) {
            case TakingLand:
                entityId = takingLandEntity;
                break;
            case Project:
                entityId = projectEntity;
                break;
            default:
                entityId = developerEntity;
        }

        return entityId;
    }

    public <T extends QueryMetricRequestDto> T setCommonData(T dto) {
        dto.setProject(this.project_code);
        return dto;
    }

    public Map<String, Object> getDeveloperMainData(String creditCode) {
        ArrayList<String> tagsId = this.getDeveloperTagsIdList();

        GetDeveloperFilterDataRequestDto dto = new GetDeveloperFilterDataRequestDto();
        dto = this.setCommonData(dto);
        dto.setTable_name(DeveloperService.DEVELOPER_MAIN);
        dto.setPage(1);
        dto.setPage_size(1);
        dto.addFilterDtos("organizing_code", BaseTjFilterDto.OPERATE_EQUAL, creditCode, DeveloperService.DEVELOPER_MAIN, BaseTjFilterDto.ASSOCIATE_NONE);
        dto.setTag_ids(tagsId);

        BaseTjListResponseDto res = getDeveloperDataService.getDeveloperMainAndDetailData(dto);

        ArrayList<BaseTjListItemDto> list = res.getData().getList();
        if (list == null || list.size() == 0) {
            return new HashMap<>();
        }
        Map<String, Object> item = list.get(0).getItem();

        List<String> creditCodeList = new ArrayList<>();
        creditCodeList.add(creditCode);
        HashMap<String, Integer> developerScoreMap = this.getDeveloperScoreMapByCreditCodeList(creditCodeList);
        item.put("developer_score", developerScoreMap.get(creditCode));

        // 标签特殊处理
        ArrayList<Map<String, Object>> tagsData = res.getData().getList().get(0).getTag_infos();
        if (tagsData != null) {
            // 顶级公司逻辑
            String topCompanyType = labelService.extractAndDeleteTagValueNameWithTagName(tagsData, TjEntity.Developer, LabelService.LABEL_TOP_COMPANY_TYPE);
            if (!topCompanyType.equals("")) {
                item.put("top_company_type_label", topCompanyType);
            }
            List<String> tagsStrArray = tagsData.stream().map(c -> {
                return c.getOrDefault("tag_value", "").toString();
            }).collect(Collectors.toList());
            List<List<LabelStyleConfig>> renderedTags = labelService.batchLoadLabelFromCommaString((ArrayList<String>) tagsStrArray);
            item.put("tags", renderedTags);
        }
        // Logo特殊处理
        if (item.get("developer_id") != null && item.get("developer_logo") != null) {
            item.put("developer_logo", ycgFileService.getEnterpriseLogo(item.get("developer_id").toString(), item.get("developer_logo").toString()));
        }
        // 资金特殊处理
        if (item.get("regist_capi") != null) {
            item.put("regist_capi", item.getOrDefault("regist_capi", 0).toString() + item.getOrDefault("regist_capi_unit", "万元"));
        }
        if (item.get("rec_capi") != null) {
            item.put("rec_capi", item.getOrDefault("rec_capi", 0).toString() + item.getOrDefault("rec_capi_unit", "万元"));
        }
        //数据状态
        if (item.get("organizing_code") != null) {
            item.put("oppty_status", commonService.getOpptyStatus(CommonService.BigDataType.DEVELOPER.toString(), item.get("organizing_code").toString(), true));
        }

        return item;
    }

    public ArrayList<BaseTjListItemDto> getDeveloperMainDataMulti(List<String> creditCodeList) {
        ArrayList<String> tagsId = this.getDeveloperTagsIdList();

        GetDeveloperFilterDataRequestDto dto = new GetDeveloperFilterDataRequestDto();
        dto = this.setCommonData(dto);
        dto.setTable_name(DeveloperService.DEVELOPER_MAIN);
        dto.setPage(1);
        dto.setPage_size(1000000);
        dto.addFilterDtos("organizing_code", BaseTjFilterDto.OPERATE_CONTAIN, Joiner.on(",").join(creditCodeList), DeveloperService.DEVELOPER_MAIN, BaseTjFilterDto.ASSOCIATE_NONE);
        dto.setTag_ids(tagsId);
        BaseTjListResponseDto res = getDeveloperDataService.getDeveloperMainAndDetailData(dto);
        ArrayList<BaseTjListItemDto> list = res.getData().getList();
        if (list.size() == 0) {
            return new ArrayList<>();
        }
        //调用opensearch,获取采购商得分
        HashMap<String, Integer> developerScoreMap = this.getDeveloperScoreMapByCreditCodeList(creditCodeList);
        list.forEach(row -> {
            Map<String, Object> item = row.getItem();

            // 标签特殊处理
            ArrayList<Map<String, Object>> tagsData = row.getTag_infos();
            if (tagsData != null) {
                // 顶级公司逻辑
                String topCompanyType = labelService.extractAndDeleteTagValueNameWithTagName(tagsData, TjEntity.Developer, LabelService.LABEL_TOP_COMPANY_TYPE);
                if (!topCompanyType.equals("")) {
                    item.put("top_company_type_label", topCompanyType);
                }
                List<String> tagsStrArray = tagsData.stream().map(c -> {
                    return c.getOrDefault("tag_value", "").toString();
                }).collect(Collectors.toList());
                List<List<LabelStyleConfig>> renderedTags = labelService.batchLoadLabelFromCommaString((ArrayList<String>) tagsStrArray);
                item.put("tags", renderedTags);
            }
            // Logo特殊处理
            item.put("developer_logo", ycgFileService.getEnterpriseLogo(item.get("developer_id").toString(), item.get("developer_logo").toString()));
            // 资金特殊处理
            item.put("regist_capi", item.getOrDefault("regist_capi", 0).toString() + item.getOrDefault("regist_capi_unit", "万元"));
            item.put("rec_capi", item.getOrDefault("rec_capi", 0).toString() + item.getOrDefault("rec_capi_unit", "万元"));

            String organizingCode = item.get("organizing_code").toString();
            Integer developerScore = developerScoreMap.get(organizingCode);
            item.put("developer_score", developerScore);
        });
        return list;
    }

    public List<CheckMainDataResponseDto> getDeveloperMainDataMultiName(List<String> developerNameList) {
        ArrayList<String> tagsId = this.getDeveloperTagsIdList();

        GetDeveloperFilterDataRequestDto dto = new GetDeveloperFilterDataRequestDto();
        dto = this.setCommonData(dto);
        dto.setTable_name(DeveloperService.DEVELOPER_MAIN);
        dto.setPage(1);
        dto.setPage_size(1000000);
        dto.addFilterDtos("developer_name", BaseTjFilterDto.OPERATE_CONTAIN, Joiner.on(",").join(developerNameList), DeveloperService.DEVELOPER_MAIN, BaseTjFilterDto.ASSOCIATE_NONE);
        dto.setTag_ids(tagsId);

        BaseTjListResponseDto res = getDeveloperDataService.getDeveloperMainAndDetailData(dto);

        ArrayList<BaseTjListItemDto> list = res.getData().getList();

        List<String> creditCodeList = new ArrayList<>();
        list.forEach(p -> {
            if (p != null && p.getItem() != null && p.getItem().get("organizing_code") != null) {
                creditCodeList.add(p.getItem().get("organizing_code").toString());
            }
        });
        HashMap<String, Integer> developerScoreMap = this.getDeveloperScoreMapByCreditCodeList(creditCodeList);

        List<CheckMainDataResponseDto> checkDeveloperMainData = new ArrayList<>();
        developerNameList.forEach(d -> {
            CheckMainDataResponseDto checkMainDataResponseDto = new CheckMainDataResponseDto();
            checkMainDataResponseDto.setDeveloperName(d);
            checkMainDataResponseDto.setIsInMainData(0);
            checkMainDataResponseDto.setDeveloperScore("");
            list.forEach(p -> {
                if (p.getItem().get("developer_name").equals(d)) {
                    checkMainDataResponseDto.setIsInMainData(1);
                    checkMainDataResponseDto.setOrganizingCode(p.getItem().get("organizing_code").toString());
                    Integer score = developerScoreMap.get(p.getItem().get("organizing_code").toString());
                    if (score != null) {
                        checkMainDataResponseDto.setDeveloperScore(score);
                    }
                }
            });
            checkDeveloperMainData.add(checkMainDataResponseDto);
        });

        return checkDeveloperMainData;
    }

    public Object applyDeveloperMainData(ApplyDeveloperMainDataDto reqDto) {
        OpenapiClientService openapiClientService = openapiClientFactoryService.getOpenapiService();
        Object result = new HashMap<>();

        try {
            ApplyMainDataReqDto applyMainDataReqDto = new ApplyMainDataReqDto();
            List<ApplyMainDataReqDto.Developers> applyList = new ArrayList<ApplyMainDataReqDto.Developers>();
            // 获取租户 code
            String tenantCode = contextManager.fetchContextInfo().getTenantCode();
            reqDto.getDevelopers().forEach(developer -> {
                ApplyMainDataReqDto.Developers company = new ApplyMainDataReqDto.Developers();
                company.setCompany_name(developer.getName());
                company.setSource("5");
                // 租户CODE + 业务类型 + 业务id
                company.setSource_id(tenantCode + "_" + developer.getType() + "_" + developer.getBusinessId());
                applyList.add(company);
            });

            // 设置参数调用反哺接口
            applyMainDataReqDto.setType("kfs");
            applyMainDataReqDto.setData(applyList);
            ApplyMainDataRespDto resp = openapiClientService.applyDeveloperMainData(applyMainDataReqDto);
            result = resp.getData();
        } catch (Exception e) {
            result = e.toString();
        }

        return result;
    }

    public Object applySupplierMainData(ApplyDeveloperMainDataDto reqDto) {
        OpenapiClientService openapiClientService = openapiClientFactoryService.getOpenapiService();
        Object result = new HashMap<>();

        try {
            ApplyMainDataReqDto applyMainDataReqDto = new ApplyMainDataReqDto();
            List<ApplyMainDataReqDto.Developers> applyList = new ArrayList<ApplyMainDataReqDto.Developers>();
            // 获取租户 code
            String tenantCode = contextManager.fetchContextInfo().getTenantCode();
            reqDto.getSupplier().forEach(developer -> {
                ApplyMainDataReqDto.Developers company = new ApplyMainDataReqDto.Developers();
                company.setCompany_name(developer.getName());
                company.setSource("5");
                // 租户CODE + 业务类型 + 业务id
                company.setSource_id(tenantCode + "_" + developer.getType() + "_" + developer.getBusinessId());
                applyList.add(company);
            });

            // 设置参数调用反哺接口
            applyMainDataReqDto.setType("gys");
            applyMainDataReqDto.setData(applyList);
            ApplyMainDataRespDto resp = openapiClientService.applyDeveloperMainData(applyMainDataReqDto);
            result = resp.getData();
        } catch (Exception e) {
            result = e.toString();
        }

        return result;
    }

    //批量获取指标数据
    public List<Map<String, Object>> getMetricListByCreditCodeList(List<String> creditCodeList) {
        GetDeveloperFilterDataRequestDto dto = new GetDeveloperFilterDataRequestDto();

        dto = this.setCommonData(dto);
        dto.setDetail_table_name(DeveloperService.TABLE_METRICS);
        dto.setPage(1);
        dto.setPage_size(1000);
        dto.addFilterDtos("organizing_code", BaseTjFilterDto.OPERATE_CONTAIN, StringUtil.join(creditCodeList, ","), DeveloperService.TABLE_METRICS, BaseTjFilterDto.ASSOCIATE_NONE);


        BaseTjListResponseDto res = getDeveloperDataService.getFilteredDeveloperDetailList(dto);
        List<Map<String, Object>> metrics = new LinkedList<>();

        res.getData().getList().forEach(i -> {
            metrics.add(i.getItem());
        });

        return metrics;
    }

    public HashMap<String, Integer> getDeveloperScoreMapByCreditCodeList(List<String> creditCodeList) {
        HashMap<String, Integer> developerScoreMap = new HashMap<>();
        GetSubscriptionConfigRequestDto getSubscriptionConfigRequestDto = new GetSubscriptionConfigRequestDto();
        getSubscriptionConfigRequestDto.setType(GetSubscriptionConfigRequestDto.SubscriptionType.RadarSubscription);
        GetSubscriptionConfigResponseDto config = remoteSubscriptionService.getSubscriptionConfig(getSubscriptionConfigRequestDto);
        String landUsage = "";
        String projectType = "";
        if (config != null) {
            landUsage = config.getLandUsage();
            projectType = config.getProjectType();
        }
        OpensearchClientService service = opensearchClientFactoryService.getOpensearchService();
        GetDeveloperScoreRequestDto scoreRequestDto = new GetDeveloperScoreRequestDto();
        scoreRequestDto.setOrganizing_code(Joiner.on(",").join(creditCodeList));
        scoreRequestDto.setSubscription_project_type(projectType);
        scoreRequestDto.setSubscription_land_usage(landUsage);
        OpenSearchSingleListResponseDto responseDto = service.getDeveloperScore(scoreRequestDto);
        if (responseDto != null && responseDto.getData() != null) {
            responseDto.getData().forEach(item -> {
                if (item.get("developer_score") != null && item.get("organizing_code") != "") {
                    developerScoreMap.put((String) item.get("organizing_code"), (Integer) item.get("developer_score"));
                }
            });
        }
        return developerScoreMap;
    }

    public Map<String, Object> getMetrics(String creditCode) {
        if (creditCode == null || creditCode.equals("")) {
            return new HashMap<>();
        }
        // 1、取指标数据
        GetDeveloperFilterDataRequestDto dto = new GetDeveloperFilterDataRequestDto();

        dto = this.setCommonData(dto);
        dto.setTable_name(DeveloperService.TABLE_METRICS);
        dto.setIdentity_value(creditCode);
        dto.setPage(1);
        dto.setPage_size(1000);

        BaseTjListResponseDto res = getDeveloperDataService.getDeveloperDetailData(dto);
        Map<String, Object> metrics = new HashMap<>();
        if (res.getData().getList() != null && res.getData().getList().size() > 0) {
            metrics = res.getData().getList().get(0).getItem();
        }

        // 2、取线索数据
        GetDeveloperDataDto getDeveloperDataDto = new GetDeveloperDataDto();
        getDeveloperDataDto.setCreditCode(creditCode);
        metrics.put("clue_count", clueService.countClue(getDeveloperDataDto));

        // 3、取风险数据
        // this.putRiskCountInMetrics(metrics, creditCode);

        // 4、取雷达数据
        try {
            DeveloperMetricDto developerMetricDto = new DeveloperMetricDto();

            developerMetricDto.setNearly_a_year_taken_land(Double.valueOf(metrics.getOrDefault("nearly_a_year_taken_land", "0").toString()));
            developerMetricDto.setNearly_a_year_open_project(Double.valueOf(metrics.getOrDefault("nearly_a_year_open_project", "0").toString()));
            developerMetricDto.setCommence_permit_cnt_1year(Double.valueOf(metrics.getOrDefault("commence_permit_cnt_1year", "0").toString()));
            DeveloperActivityRadarDto developerActivityRadarDto = getActivityRadar(creditCode, developerMetricDto);
            metrics.put("radar_taking_land", developerActivityRadarDto.getTake_land_score());
            metrics.put("radar_project", developerActivityRadarDto.getProject_score());
            metrics.put("radar_commence_permit", developerActivityRadarDto.getCommence_permit_score());
        } catch (IllegalArgumentException e) {
            log.error(e.getMessage());
        }

        return metrics;
    }

    public Object getDeveloperDetailRiskCount(String creditCode) {
        Map<String, Object> metrics = new HashMap<>();
        this.putRiskCountInMetrics(metrics, creditCode);

        return metrics;
    }

    protected void putRiskCountInMetrics(Map<String, Object> metrics, String creditCode) {
        RiskTabRequestDto rDto = new RiskTabRequestDto();
        rDto.setKeyword(creditCode);
        rDto.setPage_num(1);
        rDto.setPage_size(10);
        rDto.setTab_codes(new ArrayList<String>() {
            {
                add("QccGetSupplierZX");
                add("QccGetSupplierCourtRegister");
                add("QccGetSupplierLawSuit");
                add("QccGetSupplierRelaTaxIllegal");
            }
        });
        try {
            BasicOpensearchResponse riskTabRes = getDeveloperDataService.getRiskTabStatistics(rDto);

            int totalRiskCount = 0;
            BasicOpenSearchDataDto riskTabDataContainer = riskTabRes.getData();
            if (riskTabDataContainer == null) {
                return;
            }
            ArrayList<Map<String, Object>> riskTabData = riskTabDataContainer.getItems();
            for (int r = 0; r < riskTabData.size(); r++) {
                metrics.put(riskTabData.get(r).get("tab").toString(), riskTabData.get(r).get("value"));
                totalRiskCount += Integer.valueOf(riskTabData.get(r).get("value").toString());
            }
            metrics.put("riskTotal", totalRiskCount);
        } catch (MipSdkException e) {
            metrics.put("QccGetSupplierZX", 0);
            metrics.put("QccGetSupplierCourtRegister", 0);
            metrics.put("QccGetSupplierLawSuit", 0);
            metrics.put("QccGetSupplierRelaTaxIllegal", 0);
            metrics.put("riskTotal", 0);
        }
    }

    protected CustomerDto getCustomer(String creditCode) {
        GetCustomerRequestDto dto = new GetCustomerRequestDto();
        dto.setCreditCode(creditCode);
        User authenticationUser = ThreadContextHolder.getInstance().get(AuthenticationUser.class);
        dto.setCustomerResponsiblePersonGUID(authenticationUser.getUserId());
        return remoteCustomerService.getCustomerByCode(dto);
    }

    //获取数芯所有标签id列表
    public ArrayList<String> getDeveloperTagsIdList() {
        ArrayList<TagDto> tagsData = getDeveloperTags();
        ArrayList<String> tags = new ArrayList<>();
        tagsData.forEach(t -> {
            tags.add(t.getTag_id());
        });

        return tags;
    }

    public ArrayList<TagDto> getDeveloperTags() {
        return labelService.getTagsByScene(TjEntity.Developer, LabelService.SCENE_DEVELOPER_MAIN);
    }


    public ArrayList<TagDto> getAllTags() {
        ArrayList<String> tags = new ArrayList<>();
        ArrayList<TagDto> tagsData = getDeveloperDataServiceAgent.getAllTags(this.project_code, this.developerEntity);
        return tagsData;
    }

    public Object getDeveloperMainDataAndSummary(String creditCode) {
        if (creditCode.isEmpty()) {
            return new HashMap<>();
        }

        Map<String, Object> data = this.getDeveloperMainData(creditCode);

        Map<String, Object> metrics = this.getMetrics(creditCode);
        data.put("metrics", metrics);

        CustomerDto customerDto = this.getCustomer(creditCode);
        data.put("customer", customerDto);

        int hasAddCustomer = this.getHasAddCustomer(creditCode);
        data.put("has_added", hasAddCustomer);

        return data;
    }

    private int getHasAddCustomer(String creditCode) {
        List<String> creditCodes = new ArrayList<>();
        creditCodes.add(creditCode);

        Set<String> haveAdded = remoteCustomerService.isAdded(creditCodes);
        // 是否添加过
        int hasAdded = haveAdded.contains(creditCode) ? 1 : 0;
        return hasAdded;
    }

    /**
     * 获取招标详情
     * 招标的详情分为 云采购平台招标，官网招标，公共交易中心（八爪鱼和购买），门户招标
     * 招标的详情内容取值也会有所不同
     * 对于平台的招标，门户的招标，八爪鱼爬取的 直接取的数据中心
     * 对于购买的数据取的是 oss 内容
     *
     * @param id string 招标id
     * @return Object
     */
    public Object getOpportunityDetail(String id) {
        BasicYcgObjectResponseDto res = getDeveloperDataService.searchOpportunityDetail(id);
        if (res.getData() == null) {
            throw new BusinessLogicException("招标详情不存在: " + id);
        }
        Map<String, Object> m = res.getData();

        // 处理没有发布和截止时间的问题
        m.putIfAbsent("publish_time", "");
        m.putIfAbsent("end_time", "");

        // 脱敏数据
        if (m.get("ower") != null) {
            m.put("ower", MyStringUtil.spiltString(m.get("ower").toString()));//切割姓名，取第一个
            m.put("ower", MyStringUtil.ReplaceSpecifiedStr(0, 1, m.get("ower").toString(), "*", 2));
        }
        if (m.get("ower_mobile") != null) {
            m.put("ower_mobile", MyStringUtil.spiltString(m.get("ower_mobile").toString()));//切割手机号，取第一个
            m.put("ower_mobile", MyStringUtil.ReplaceSpecifiedStr(0, 3, m.get("ower_mobile").toString(), "*", 8));
        }
        if (m.get("agent_ower") != null) {
            m.put("agent_ower", MyStringUtil.ReplaceSpecifiedStr(0, 1, m.get("agent_ower").toString(), "*", 2));
        }
        if (m.get("agent_ower_mobile") != null) {
            m.put("agent_ower_mobile", MyStringUtil.ReplaceSpecifiedStr(0, 3, m.get("agent_ower_mobile").toString(), "*", 8));
        }

        // 处理电话
        if (m.get("data_source") != null && ("平台公开招标".equals(m.get("data_source")) || "平台招募".equals(m.get("data_source")))) {
            String phone = "";
            if (m.get("ower_mobile") != null) {
                phone = m.get("ower_mobile").toString();
            }
            if (phone.length() > 7) {
                m.put("ower_mobile", phone.substring(0, 3) + "****" + phone.substring(7));
            }
            m.put("ower_mobile_visible", false);
        } else {
            m.put("ower_mobile_visible", true);
        }

        List<String> wrapper = new ArrayList<>();
        wrapper.add(id);
        Set<String> added = clueService.isAdded(wrapper);
        if (added.contains(id)) {
            m.put("has_added", 1);
        } else {
            m.put("has_added", 0);
        }

        // 处理省市
        if (m.get("projects") != null) {
            OpportunityProjectDto projectDto = searchService.getProvinceAndCityFromProject(m.get("projects"));
            m.put("city", projectDto.getCity());
            m.put("province", projectDto.getProvince());
        }

        // 历史问题先兼容，重构时把这个字段去掉
        m.put("content_html", "");
        // 处理详情，优先获取oss文件内容作为中标详情
        String detail = "";
        m.put("detail", detail);
        try {
            if (m.get("publish_time") != null && m.get("website_name") != null && m.get("content_id") != null) {
                String filePath = OssUtil.getBidNoticeFilePath(m.get("publish_time").toString(), m.get("website_name").toString(), m.get("content_id").toString());
                if (!filePath.equals("")) {
                    String contentHtml = OssUtil.getOssFile(filePath);
                    m.put("content_html", contentHtml);
                }
            }
        } catch (IOException exception) {
            m.put("content_html", "暂无原文数据");
        }
        //数据状态
        if (m.get("id") != null) {
            m.put("oppty_status", commonService.getOpptyStatus(CommonService.BigDataType.PURCHASE.toString(), m.get("id").toString(), true));
        }
        // 如果 OSS 拿不到则从接口拿
        if (m.get("detail").toString().isEmpty()) {
            BigDataClientService bigDataClientService = bigDataClientFactoryService.getBigDataClientService();
            GetPurchaseDetailRequestDto getPurchaseDetailRequestDto = new GetPurchaseDetailRequestDto();
            getPurchaseDetailRequestDto.setId(id);
            GetPurchaseDetailResponseDto getPurchaseDetailResponseDto = bigDataClientService.GetPurchaseDetail(getPurchaseDetailRequestDto);
            if (getPurchaseDetailResponseDto.getData().size() > 0) {
                detail = getPurchaseDetailResponseDto.getData().get(0).getDetail();
                if (detail == null || detail.isEmpty()) {
                    // 兼容老逻辑，之后需要删除
                    if (m.get("data_source_code") != null && ("trading_center".equals(m.get("data_source_code")) || "website_bid".equals(m.get("data_source_code")))) {
                        UidRequestDto dto = new UidRequestDto();
                        dto.setUid(m.get("uid").toString());
                        SqlApiListResponseDto tradingCenterDetail = getDeveloperDataService.getTradingCenterDetail(dto);
                        if (tradingCenterDetail.getData().size() > 0) {
                            m.put("detail", this.getTradingCenterDetailHtml(tradingCenterDetail.getData().get(0)));
                        }
                        // YcgResponseOnlyMapDto detail = getDeveloperDataService.getProcurementByUid(m.get("uid").toString());
                        //  m.put("detail", detail.getData().get("detail"));
                    }
                } else {
                    m.put("detail", detail);
                }
            }
        }

        return m;
    }

    public boolean addCustomers(AddCustomersRequestDto customerDtos) {
        remoteCustomerService.addCustomers(customerDtos);
        return true;
    }

    public Object getOpenedTradingData(String creditCode, GetOpenedTradingFilterDto filters, PagerDto pager) {
        GetDeveloperFilterDataRequestDto dto = new GetDeveloperFilterDataRequestDto();

        dto = this.setCommonData(dto);
        dto.setTable_name(DeveloperService.TABLE_OPENED_TRADING);
        dto.setIdentity_value(creditCode);
        dto.setPage(pager.getPage());
        dto.setPage_size(pager.getPage_size());
        dto.addFilterDtos("organizing_code", BaseTjFilterDto.OPERATE_EQUAL, filters.getSubCompanyCreditCode(), DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);
        dto.addFilterDtos("province", BaseTjFilterDto.OPERATE_EQUAL, filters.getProvince(), DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);
        dto.addFilterDtos("property_category", BaseTjFilterDto.OPERATE_EQUAL, filters.getType(), DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);
        dto.addFilterDtos("decorate", BaseTjFilterDto.OPERATE_EQUAL, filters.getDeliveryType(), DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);

        if (filters.getYear() > 0) {
            String openingTimeBegin = timeService.convertYearToTimeString(filters.getYear());
            String openingTimeEnd = timeService.convertYearToNextYearTimeString(filters.getYear());
            dto.addFilterDtos("opening_time", BaseTjFilterDto.OPERATE_LARGER_EQUAL, openingTimeBegin, DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);
            dto.addFilterDtos("opening_time", BaseTjFilterDto.OPERATE_LESS, openingTimeEnd, DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);
        }


        dto.addFilterDtos("price", BaseTjFilterDto.OPERATE_LESS_EQUAL, filters.getUnitPriceUpperBound(), DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);
        dto.addFilterDtos("price", BaseTjFilterDto.OPERATE_LARGER_EQUAL, filters.getUnitPriceLowerBound(), DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);

        BaseTjListResponseDto res = getDeveloperDataService.getDeveloperDetailData(dto);
        return res.getData();
    }

    public Object getProcurementRequirementData(String creditCode, GetProcurementRequirementFilterDto filters, PagerDto pager) {
        GetDeveloperFilterDataRequestDto dto = new GetDeveloperFilterDataRequestDto();

        dto = this.setCommonData(dto);
        dto.setTable_name(DeveloperService.TABLE_PROCUREMENT_REQUIREMENT);
        dto.setIdentity_value(creditCode);
        dto.setPage(pager.getPage());
        dto.setPage_size(pager.getPage_size());
        dto.addFilterDtos("organizing_code", BaseTjFilterDto.OPERATE_EQUAL, filters.getSubCompanyCreditCode(), DeveloperService.TABLE_OPENED_TRADING, BaseTjFilterDto.ASSOCIATE_NONE);

        BaseTjListResponseDto res = getDeveloperDataService.getDeveloperDetailData(dto);
        return res.getData();
    }

    @Override
    //高级筛选-找客户查询
    public BaseTjListDto getDeveloperDetailData(GetDeveloperFilterDataRequestDto getDeveloperFilterDataRequestDto) {
//        GetDeveloperFilterDataRequestDto getDeveloperFilterDataRequestDto = new GetDeveloperFilterDataRequestDto();
//        getDeveloperFilterDataRequestDto = dto;
        this.setCommonData(getDeveloperFilterDataRequestDto);
//        ArrayList<BaseTjFilterDto> baseTjFilterDtos = new ArrayList<BaseTjFilterDto>();
//        BaseTjFilterDto baseTjFilterDto = new BaseTjFilterDto();
//        baseTjFilterDto.setAttribute_name("developer_name");
//        baseTjFilterDto.setOperate(11);
//        baseTjFilterDto.setValue("星河");
//        baseTjFilterDto.setTable_name("dim_ycg_common_developer_m");
//        baseTjFilterDto.setAssociate_previous(0);
//        baseTjFilterDtos.add(baseTjFilterDto);
//        getDeveloperFilterDataRequestDto.setFilters(baseTjFilterDtos);
//        ArrayList<String> tagsIds = this.getDeveloperTags();
//        getDeveloperFilterDataRequestDto.setTag_ids(tagsIds);

        // 标签搜索筛选代码，后续可以删掉
//        ArrayList<TagFilter> filters = new ArrayList<>();
//        TagFilter f = new TagFilter();
//        f.setTag_id("2ba35521-0a5b-11ed-90d2-567a60145203");
//        ArrayList<String> tagValues = new ArrayList<>();
//        tagValues.add("d8c7c60b-0a5e-11ed-90d2-567a60145203");
//        f.setTag_value_id(tagValues);
//        filters.add(f);
//        dto.setTag_filters(filters);

        BaseTjListResponseDto baseTjListResponseDto = getDeveloperDataService.getDeveloperMainAndDetailData(getDeveloperFilterDataRequestDto);
        System.out.println("getDeveloperFilterDataRequestDto=====================" + getDeveloperFilterDataRequestDto);
        System.out.println("baseTjListResponseDto=====================" + baseTjListResponseDto);
        return baseTjListResponseDto.getData();
    }

    @Override
    //高级筛选-找商机查询
    public BaseTjListDto searchOpptyPurchase(GetDeveloperFilterDataRequestDto getDeveloperFilterDataRequestDto) {
        this.setCommonData(getDeveloperFilterDataRequestDto);
        BaseTjListResponseDto baseTjListResponseDto = getDeveloperDataService.getFilteredDeveloperDetailList(getDeveloperFilterDataRequestDto);
        System.out.println("getDeveloperFilterDataRequestDto=====================" + getDeveloperFilterDataRequestDto);
        System.out.println("baseTjListResponseDto=====================" + baseTjListResponseDto);
        return baseTjListResponseDto.getData();
    }

    @Override
    //批量获取指标数据
    public BaseTjListDto getMetricsList(List<String> organizingCodeList, int page, int pageSize) {
        GetDeveloperFilterDataRequestDto getDeveloperFilterDataRequestDto = new GetDeveloperFilterDataRequestDto();
        getDeveloperFilterDataRequestDto.setPage_size(pageSize);
        getDeveloperFilterDataRequestDto.setPage(page);
        getDeveloperFilterDataRequestDto.setDetail_table_name(DeveloperService.TABLE_METRICS);
        ArrayList<BaseTjFilterDto> baseTjFilterDtos = new ArrayList<>();
        BaseTjFilterDto baseTjFilterDto = new BaseTjFilterDto();
        baseTjFilterDto.setValue(Joiner.on(",").join(organizingCodeList));
        baseTjFilterDto.setOperate(BaseTjFilterDto.OPERATE_CONTAIN);
        baseTjFilterDto.setTable_name(DeveloperService.TABLE_METRICS);
        baseTjFilterDto.setAssociate_previous(0);
        baseTjFilterDto.setAttribute_name("organizing_code");
        baseTjFilterDtos.add(baseTjFilterDto);
        getDeveloperFilterDataRequestDto.setFilters(baseTjFilterDtos);
        this.setCommonData(getDeveloperFilterDataRequestDto);
        BaseTjListResponseDto baseTjListResponseDto = getDeveloperDataService.getFilteredDeveloperDetailList(getDeveloperFilterDataRequestDto);
        System.out.println("getDeveloperFilterDataRequestDto=====================" + getDeveloperFilterDataRequestDto);
        System.out.println("baseTjListResponseDto=====================" + baseTjListResponseDto);
        return baseTjListResponseDto.getData();
    }

    public ListDataResult getTjResFromLoadData(BaseTjListResponseDto res) {
        return getTjResFromLoadData(res, new TjResultMapChangerService() {
        });
    }

    public ListDataResult getSqlApiResFromLoadData(SqlApiResponseDto res) {
        ListDataResult result = new ListDataResult();
        ArrayList<Object> output = new ArrayList<>();

        List<Map<String, Object>> list = res.getData().getRows();
        if (list == null) {
            result.setData(list);
            result.setTotal(0);
        } else {
            res.getData().getRows().forEach(r -> {
                Map<String, Object> map = setTjRes(r);
                output.add(map);
            });
            result.setData(output);
            result.setTotal(res.getData().getTotalNum());
        }
        return result;
    }

    public ResponseDataDto getSqlApiRes(SqlApiResponseDto res) {
        ResponseDataDto responseDataDto = new ResponseDataDto();
        responseDataDto.setPageNum(1);
        responseDataDto.setPageSize(1000);
        responseDataDto.setTotalNum(0);
        if (res.getErrCode() == 0) {
            if (res.getData().getRows().size() > 0) {
                return res.getData();
            }
        }
        return responseDataDto;
    }

    public ListDataResult getTjResFromLoadData(BaseTjListResponseDto res, TjResultMapChangerService tjResultMapChangerService) {
        ListDataResult result = new ListDataResult();

        ArrayList<Object> output = new ArrayList<>();

        ArrayList<BaseTjListItemDto> list = res.getData().getList();
        if (list == null) {
            result.setData(list);
            result.setTotal(0);
        } else {
            res.getData().getList().forEach(r -> {
                tjResultMapChangerService.change(r);
                Map<String, Object> map = setTjRes(r.getItem());
                output.add(map);
            });
            result.setData(output);
            result.setTotal(res.getData().getTotal());
        }

        return result;
    }

    public Map<String, Object> setTjRes(Map<String, Object> map) {
        map.put("uuid", UUID.randomUUID().toString());

        // 如果有sub_company_name或者sub_organizing_code时，证明数据源是有股权关系的数据源，我们使用子公司信息代替原本信息
        if (map.get("sub_organizing_code") != null) {
            map.put("organizing_code", map.get("sub_organizing_code"));
            map.put("developer_name", map.get("sub_developer_name"));
        }

        // 根据实际值补充
        if (map.get("new_house_deal_money") == null || map.get("new_house_deal_money").equals("")) {
            map.put("new_house_deal_money", "--");
        } else {
            map.put("new_house_deal_money", map.get("new_house_deal_money") + "万元");
        }

        if (map.get("new_house_deal_num") == null || map.get("new_house_deal_num").equals("")) {
            map.put("new_house_deal_num", "--");
        } else {
            map.put("new_house_deal_num", map.get("new_house_deal_num") + "套");
        }

        if (map.get("new_house_sale_rate") == null || map.get("new_house_sale_rate").equals("")) {
            map.put("new_house_sale_rate", "--");
        } else {
            map.put("new_house_sale_rate", map.get("new_house_sale_rate") + "%");
        }


        return map;
    }

    public String getTradingCenterDetailHtml(Map<String, Object> res) {
        String html = "";
        html += "<p>项目编号：" + this.getSafeMapItem(res, "project_number") + "</p>";
        html += "<p>项目名称：" + this.getSafeMapItem(res, "project_name") + "</p>";
        html += "<p>项目所在地：" + this.getSafeMapItem(res, "address") + "</p>";
        html += "<p>招标单位：" + this.getSafeMapItem(res, "developer_name") + "</p>";
        html += "<p>招标单位地址：" + this.getSafeMapItem(res, "ower_address") + "</p>";
        html += "<p>招标单位联系电话：" + MyStringUtil.ReplaceSpecifiedStr(0, 3, this.getSafeMapItem(res, "ower_phone"), "*", 8) + "</p>";
        html += "<p>招标单位联系人：" + MyStringUtil.ReplaceSpecifiedStr(0, 1, this.getSafeMapItem(res, "ower_contact"), "*", 2) + "</p>";
        html += "<p>代理机构：" + this.getSafeMapItem(res, "agent_unit") + "</p>";
        html += "<p>代理机构联系电话：" + MyStringUtil.ReplaceSpecifiedStr(0, 3, this.getSafeMapItem(res, "agent_phone"), "*", 8) + "</p>";
        html += "<p>代理机构联系人：" + MyStringUtil.ReplaceSpecifiedStr(0, 1, this.getSafeMapItem(res, "agent_contact"), "*", 2) + "</p>";
        html += "<p>代理机构地址：" + this.getSafeMapItem(res, "agent_address") + "</p>";
        html += "<p>建设规模：" + this.getSafeMapItem(res, "build_scale") + "</p>";
        html += "<p>业务类型：" + this.getSafeMapItem(res, "business_type") + "</p>";
        html += "<p>工期：" + this.getSafeMapItem(res, "construction_time_limit") + "</p>";
        html += "<p>资格要求：" + this.getSafeMapItem(res, "qualification") + "</p>";
        html += "<p>业务类型：" + this.getSafeMapItem(res, "business_type") + "</p>";
        html += "<p>资金来源：" + this.getSafeMapItem(res, "fund_source") + "</p>";
        html += "<p>项目预算（投标最高限价）：" + this.getSafeMapItem(res, "budget") + "</p>";
        //html += "开标日期：" + res.get("open_time").toString() + "</p>";

        return html;
    }

    private String getSafeMapItem(Map<String, Object> res, String key) {
        Object item = res.getOrDefault(key, "");
        if (item != null) {
            return item.toString();
        } else {
            return "";
        }
    }

    // 功能已迁移至go的租户服务oppty-service,该代码可以下线了
    public Object getDeveloperScoreDetail(String OrganizingCode) {
//        OpptyServiceClientService opptyService = opptyServiceClientFactoryService.getOpptyServiceClientService();
//        OpptyServiceResponseDto res = opptyService.getDeveloperScoreDetail(OrganizingCode);
//        if (res != null && res.getData() != null && res.getData().getOrganizing_code() != null) {
//            return res.getData();
//        }
        //这样做是为了保持返回的结构固定
        OpptyServiceResponseDto.CustomerScore emptyScore = new OpptyServiceResponseDto.CustomerScore();
        OpptyServiceResponseDto.ScoreDetail emptyDetail = new OpptyServiceResponseDto.ScoreDetail();
        emptyDetail.setDetail(new ArrayList<>());
        emptyScore.setInvestment_amount(emptyDetail);
        emptyScore.setReturn_of_fund(emptyDetail);
        emptyScore.setCredit_score(emptyDetail);
        emptyScore.setMatch_demand(emptyDetail);
        emptyScore.setAnnual_increase(emptyDetail);
        return emptyScore;
    }
}
